﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CarErp.Model;

namespace CarErp.Forms
{
	public partial class NewApplicationForm : Form
	{
		public NewApplicationForm()
			:this(null)
		{ }

		public NewApplicationForm(User user)
		{
			InitializeComponent();
			User = user;
		}

		private void button_Reset_Click(object sender, EventArgs e)
		{
			carPurchaseApplicationView.Reset();
		}

		private void button_Submit_Click(object sender, EventArgs e)
		{
			var result = carPurchaseApplicationView.GetModel();
			result.Submitter = User;
			OnApplicationCreated?.Invoke(result);
			carPurchaseApplicationView.Reset();
		}

		public event Action<CarPurchaseApplication> OnApplicationCreated;

		User User = null;
	}
}
